﻿<%@ Page Title="店铺档案" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />

<style type="text/css">
.system-box .right-side{width: 100%;}
#createYear{margin-left: 10px; padding: 5.5px 14px;}
.condition, .condition-title{position: relative; border-bottom: 1px solid #dfdfdd;}
.condition .form-control{padding: 2px 6px;}
.condition-title{
	padding: 4px 12px;
	font-size: 12px;
	font-weight: bold;
	background: #fff;
}
.suppleRate{width: 60px;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
		<div class="btns-container"></div>
		<div class="condition">
			<label>节日</label>
			<input type="text" class="form-control input-w170" id="search-festival" placeholder="节日名称" />
			<label>店铺</label>
			<input type="text" class="form-control input-w170" id="search-store" placeholder="店铺名称" />
			<label>省份</label>
			<select class="form-control input-w170" id="serarch-province">
				<option value="">请选择</option>
			</select>
			<label>城市</label>
			<select class="form-control input-w170" id="serarch-city">
				<option value="">请选择</option>
			</select>
		</div>
		<div class="condition">
			<label>时间范围</label>
            <input type="text" class="form-control layer-date" 
            	readonly="readonly" placeholder="开始时间" id="search-start" />
			<label class="to">到</label>
			<input type="text" class="form-control layer-date" 
				readonly="readonly" placeholder="结束时间" id="search-end" />
		</div>
		<div class="condition-title">参数设置</div>
		<div id="paramSet" class="condition">
			<label>设置补货系数</label>
			<input type="number" class="form-control input-w160" id="setReplenishment" placeholder="补货系数" />
		</div>
		<div class="right-content-box">
			<div class="ibox-content">
				<table class="footable table table-stripped table-list">
					<thead></thead>
					<tbody id="pageList"></tbody>
				</table>
			</div>
		</div>
			
		<div class="pageControl"></div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/plugins/iCheck/icheckAll.js"></script>

<script type="application/javascript">
$('document').ready(function(){
	//模块ID
	var ModuleID = Y.getUrlParam("ModuleID");
	//页数
	var page = 1;
	//获取按钮
	commonUtil.loadBtnList(ModuleID,function(){
		rScroll();
	});
	//初始化日期控件
	$('#search-start').val(new Date().getFullYear() + '-01-01');
	$('#search-end').val(new Date().getFullYear() + '-12-31');
	var searchstart = {
		elem: "#search-start",
		format: "YYYY-MM-DD",
		min: "2015-12-01",
		max: "2099-12-01",
		istime: false,
		istoday: false,
		choose: function (datas) {
			searchend.min = datas;
			searchend.start = datas
        }
    };
    var searchend = {
        elem: "#search-end",
        format: "YYYY-MM-DD",
        min: "2015-12-01",
        max: "2099-12-01",
        istime: false,
        istoday: false,
        choose: function (datas) {
            searchstart.max = datas
        }
    };
    laydate(searchstart);
    laydate(searchend);
	
	//绑定年份
	//commonUtil.bindDict2({DictValue: 'year'},['#Year']);
	
	var provinceList = [];
	Y.API3('OdsErpBasArea','GetAllOdsErpBasAreaList',{},function(data){
    	if(data.Success == false){
    		layer.closeAll('dialog');
    		swal(data.Message,'','error');
    	}else{
    		data.map(function(item){
    			provinceList.push(item);
    			$('#serarch-province').append('<option value="'+ item[0].ParentID +'">'+ item[0].ParentName +'</option>');
    		})
    	}
    })
	
	//选择省份
    $('#serarch-province').change(function(){
    	$('#serarch-city').empty();
    	$('#serarch-city').append('<option value="">请选择</option>');
    	var $this = $(this);
    	provinceList.map(function(item){
    		if(item[0].ParentID == $this.val()){
    			item.map(function(city){
    				$('#serarch-city').append('<option value="'+ city.AreaID +'">'+ city.AreaName +'</option>');
    			});
    			$('#serarch-city').val('');
    			return false;
    		}
    	})
    });
		
	//处理表头
	if($('.footable thead').children().size() == 0){
	    tableControl.initThead('.footable',[
			{
			    trClass: '', children: [
                	{tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllStore" />', tdId: '', tdClass: '' },
                	{tdText: '年份', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '店铺名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '日历类型', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '节日名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '对应去年日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
//              	{tdText: '去年同期取数类型', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '去年同期销售额', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '去年同期前七天日均销量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '计算补货系数', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                	{tdText: '补货系数', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
			    ]
			}
		])
	}
    
    ////全选店铺 2017-05-02改注释
	//$('.footable').on('click','thead #checkAllStore',function(){
	//	if(this.checked)
	//		$('.footable .checkStore').each(function(){this.checked=true;});
	//	else
	//		$('.footable .checkStore').each(function(){this.checked=false;});
	//});
	
    ////选中店铺 2017-05-02改注释
	//$('.footable').on('click','.checkStore',function(){
	//	if($('.footable .checkStore').size() == $('.footable .checkStore:checked').size())
	//		$('.footable #checkAllStore').prop("checked", true);
	//	else
	//		$('.footable #checkAllStore').prop("checked", false);
	//});
    
    //加载列表
    var loadList = function(){
    	var holidayKeys = $('#search-festival').val().trim().replace(/'/g, '');
    	var shopKeys = $('#search-store').val().trim().replace(/'/g, '');
    	pageControl.init('DwShopHolidayRate','GetDwShopHolidayRateList',{
	    	HolidayKeys: holidayKeys,
	    	ShopKeys: shopKeys,
	    	ProID: $('#serarch-province').val(),
	    	CityID: $('#serarch-city').val(),
	    	StartTime: $('#search-start').val(),
	    	EndTime: $('#search-end').val(),
			Page: page,
//			Size: 100,
			needLayer: true,
			alwaysCallBack:function(){
				$('#pageList').empty();
			}
		},function(result){
			page = result.page;
			var tBody = [];
			if (!Y.checkNull(result.data)) {
				if (result.data.Items.length > 0){					
					result.data.Items.map(function(item,i){
						var tempTr = {
							trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
							children: [
								{tdText:'', c:0 , r:0, tdHtml:'<input type="checkbox" class="checkStore" />', tdId:'', tdClass:''},
								{tdText:(item.HolidayYearv || ''), c:0 , r:0, tdHtml:'<input type="hidden" class="shopCode" value="'+ item.ShopCode +'" />', tdId:'', tdClass:''},
								{tdText:(item.ShopName || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.GregorianDay || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:'gregorianDay'},
								{tdText:(item.DayType || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.TypeName || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.PastYearHoliDay || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
//								{tdText:item.CalcFlag, c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.PayAmount || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.PastSevenAvgAmount || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:(item.CalcRate || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText:'', c:0 , r:0, tdHtml:'<input type="number" class="suppleRate" value="'+ item.SuppleRate +'" />', tdId:'', tdClass:''}
							]
						};
						tBody.push(tempTr);
					})
				}
				rScroll();
			}
			tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 11, null);
		    //选择全部插件 2017-05-02 改
			$(".footable").icheckAll({
			    checkObj: ".checkStore",//表格下面的选择控件对象 选择器
			    checkAllObj: "#checkAllStore",//全选 选择器
			    clickoutBoxCheck: false,//点击行 不选中
			    checkboxMargin: "4px 0 0 0 "//上右下左
			});

		})    	
    }
    loadList();
    
    //查询按钮
    $('.btns-container').on('click','#btn-search',function(){
    	page = 1;
    	loadList();
    })
    
    var saveStore = function(json){
    	layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
    	Y.API2('DwShopHolidayRate','ModDwShopHolidayRate',json,function(data){
    		layer.closeAll('dialog');
    		if(data.Success == false){
    			swal(data.Message,'','error');
    		}else{
    			swal('保存成功','','success');
    			loadList();
    		}
    	})
    }
    
    //保存按钮
    $('.btns-container').on('click','#btn-save',function(){
    	if($('#pageList .checkStore:checked').size() == 0){
    		swal('请先选择店铺');
    		return false;
    	}
    	var setReplenishment = parseFloat($('#setReplenishment').val().trim());
    	var list = [];
    	if(isNaN(setReplenishment)){
    		//单个
    		var checkRate = true;
    		$('#pageList .checkStore:checked').each(function(){
    			var tr = $(this).parents('tr');
    			if(isNaN(parseFloat(tr.find('.suppleRate').val().trim())))
    				checkRate = false;
    			list.push({
    				ShopCode: tr.find('.shopCode').val(),
    				GregorianDay: tr.find('.gregorianDay').text(),
    				SuppleRate: tr.find('.suppleRate').val()
    			})
    		})
    		if(!checkRate)
    			return false;
//  		console.log(list);
    		saveStore({list:list});
    	}else{
    		//批量
    		$('#pageList .checkStore:checked').each(function(){
    			var tr = $(this).parents('tr');
    			list.push({
    				ShopCode: tr.find('.shopCode').val(),
    				GregorianDay: tr.find('.gregorianDay').text(),
    			})
    		})
//  		console.log({
//  			list: list,
//  			newSuppleRate: setReplenishment
//  		});
    		saveStore({
    			list: list,
    			newSuppleRate: setReplenishment
    		});
    	}
    })
})
</script>
</asp:Content>

